<?php


namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Utils\ResponseUtil;

class SoulSynthesizeController extends Controller
{

   public function paginate()
   {
       $searchData = request()->all();
       global $gameArea;
       $res = callRpc("/SoulSynthesizeService/paginate",$searchData,['gameArea'=>$gameArea]);
       $data = data_get($res,'data',[]);
       foreach($data as &$datum){
           //$datum['useClmxStr'] = str_replace("\\n",'<br/>',$datum['useClmxStr']);
           //$datum['useClsxStr'] = str_replace("\\n",'<br>',$datum['useClsxStr']);
           //$datum['newClsxStr'] = str_replace("\\n",'<br/>',$datum['newClsxStr']);
       }
       return $res;
   }

    public function export(){
        $searchData = request()->all();
        global $gameArea;
        $res = callRpc("/SoulSynthesizeService/paginate",$searchData,['gameArea'=>$gameArea]);

        $excelRows = [
            ['记录时间','区服','游戏账号','角色ID','角色名','材料明细','材料属性','新装备属性',"结果次数","结果类型"]
        ];

        foreach($res['data'] as $datum) {
            $excelRows[] = [
                $datum['logTime'] ?? null,
                $datum['serverId'] ?? null,
                $datum['memberName'] ?? null,
                $datum['roleId'] ?? null,
                $datum['nick'] ?? null,
                $datum['useClmxStr'] ?? null,
                $datum['useClsxStr'] ?? null,
                $datum['newClsxStr'] ?? null,
                $datum['is_use_tz'] ?? null,
                $datum['resultTypeName'] ?? null,
            ];
        }
        return ResponseUtil::success(cacheDownload(arrayToScvContent($excelRows),'.魂魄合成.csv'));
    }

}
